package org.liulinlin.sejw.declare;

import java.sql.*;

import org.liulinlin.sejw.box.*;
import org.liulinlin.sejw.db.*;

import org.osoa.sca.annotations.Destroy;
import org.osoa.sca.annotations.Init;

public class DeclareServiceImpl implements DeclareService {
	private DBConnectionManager connMgr;
	private Params params;
	
	@Init
	public void init() {
		connMgr = DBConnectionManager.getInstance();
		params = Params.getInstance();
	}
	@Destroy
	public void destroy() {
		connMgr.release();
	}
	
	
	public DeclareComit getDeclareComitByCommId(String commId) {
		DeclareComit res = null;
		
		Connection con = connMgr.getConnection("shipping_export");
		if (con == null) {
			System.out.println("DeclareService.getDeclareComitByCommId不能获得数据库连接");
			return null;
		}
		
		try {
			Statement stmt = con.createStatement();
			ResultSet rs = stmt.executeQuery("select * from DeclareComit where Comm_ID = '" + commId + "'");
			rs.next();
			res = new DeclareComit(rs.getString("DC_ID"));
			stmt.close();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			//shutdown();
		}
		connMgr.freeConnection("shipping_export", con);
		return res;
	}
	public void setCommId(String commId) {
		params.setCommId(commId);
	}
	public String getCommId() {
		return params.getCommId();
	}
}
